from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline

# 加载模型和分词器
model_name = "distilbert-base-cased-distilled-squad"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForQuestionAnswering.from_pretrained(model_name)

# 创建 pipeline
qa = pipeline('question-answering', model=model, tokenizer=tokenizer)

# 测试
context = "Hawking was a theoretical physicist at Cambridge University."
question = "Where did Hawking work?"
result = qa(question=question, context=context)
print(result)
